﻿@{
    Layout = "~/Areas/UserOp/Views/Shared/_Layout.cshtml";
}
@using Webdiyer.WebControls.Mvc
@using Modules.Database
@using Modules.Enums
@model PagedList<TestPaper>

<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<div class="h60"></div>
<div class="part">
    <p class="position">◆当前位置：问卷列表</p>
    <div class="line_manage">
        <div class="line_manage_infor">
            <div class="h30"></div>
            <table class="table">
                <thead>
                    <tr>
                        <th>#序号</th>
                        <th>问卷标题</th>
                        <th>创建时间</th>
                        <th>回答次数</th>
                        <th>操作</th>
                        <th>问卷地址</th>
                    </tr>
                </thead>
                <tbody class="fs08 tcenter">
                    @foreach (var item in Model)
                    { 
                        <tr>
                            <th>@((int)(Model.IndexOf(item)) + 1) </th>
                            <th>@item.Title</th>
                            <th>@item.CreateTime.ToString("yyyy/MM/dd")</th>
                            <th>@item.DoCount</th>
                            <th>
                                @if (item.IsEnd == (int)EnumTestState.IsEnd)
                                {
                                    <input type="button" onclick="Start_Pause(@item.Id,this)" value="发布" class="company_btn" />
                                }
                                else
                                {
                                    <input type="button" onclick="Start_Pause(@item.Id,this)" value="暂停" class="company_btn" />
                                }
                                <input type="button" onclick="Delete(@item.Id)" value="删除" class="company_btn" />
                                <a href="~/userOP/Uhome/AddQuestions?paperid=@item.Id"> <span class="company_btn">编辑</span> </a>
                                <a href="~/userop/UAnalysis/Index?paperid=@item.Id"><span class="company_btn">分析结果</span></a>
                            </th>
                            <th><input type="text" readonly data-num="@item.Id" value="" /> </th>
                        </tr>
                    }
                </tbody>
            </table>
            <div style="text-align:center; margin-left:-2em;">
                @Html.Pager(Model, new PagerOptions
                 {
                     HorizontalAlign = "center",
                     ShowFirstLast = false,
                     CssClass = "pagination pagination-sm",
                     NavigationPagerItemWrapperFormatString = "<li>{0}</li>",
                     ContainerTagName = "ul",
                     PageIndexParameterName = "id",
                     ShowPageIndexBox = false,
                     PrevPageText = "<<",
                     NumericPagerItemCount = 3,
                     Id = "pages",
                     NextPageText = ">>",
                     CurrentPagerItemWrapperFormatString = "<li class=\"active\"> <a>{0}</a> </li>",
                     NumericPagerItemWrapperFormatString = "<li> {0}</li>",
                 }, new { style = "margin-top:2em;margin-bottom:2em" })
            </div>
        </div>
    </div>
</div>

<style>
    p {
        margin: 0 0 0px;
    }

    .main_part {
        margin-top: 20px;
    }

    a {
        color: #ffffff;
    }

        a:hover {
            text-decoration: none;
            color: #ffffff;
        }
    .table {
        font-size:18px;
    }
</style>

@section scripts{
<script>
    function Delete(id)
    {
        if (confirm("确认删除?") == false)
            return;
        $.ajax({
            url: "/UserOp/UHome/DeletePaper",
            type: "POST",
            data: {
                paperid: id
            },
            beforeSend: function (XMLHttpRequest) {
            },
            success: function (data, textStatus) {
                var object = $.parseJSON(data);
                if (object.IsOk == 1) {
                    location.reload();
                } else {
                    alert(object.Msg);
                }
            },
            error: function () {
                alert("好像出错了，刷新页面重试");
            }
        });
    }
    function Start_Pause(id,dom)
    {
        if (confirm("确认操作?") == false)
            return;
        $.ajax({
            url: "/UserOp/UHome/ChangeState",
            type: "POST",
            data: {
                paperid: id
            },
            beforeSend: function (XMLHttpRequest) {
            },
            success: function (data, textStatus) {
                var object = $.parseJSON(data);
                if (object.IsOk == 1) {
                    //location.reload();
                    dom.value = dom.value == '发布'?'暂停':'发布';
                } else {
                    alert(object.Msg);
                }
            },
            error: function () {
                alert("好像出错了，刷新页面重试");
            }
        });
    }

    $(document).ready(function () {
        var _con = $("th input[type='text']");
        var _host = location.host;
        $.each(_con, function (item) {
            _con[item].value = _host + "/UserOp/UAnswer/Paper/" + $(_con[item]).data("num");
            _con[item].onfocus = function()
            {
                this.select();
            }
        });
    });
</script>
    <script type="text/javascript">
        LeftMenuSelect(0);
    </script>
}